package gizmoball;

import java.awt.Graphics;
import java.util.ArrayList;

public class Bricks
{
	private int count;
	private ArrayList<Brick> brickList = new ArrayList<Brick>();
	public Bricks(int x, int y)
	{
		count = 0;
	}
	
	public void addBrick(Brick brick)
	{
		brickList.add(brick);
		if(brick.getProperty() == 0)
			count ++;
	}
	public void paint(Graphics g)
	{
		for(int i=0;i<brickList.size();i++)
		{
			Brick b = (Brick)brickList.get(i);
			b.paint(g);
		}
	}
	
	public int leftBrick()
	{
		return count;
	}
	
	public int collision(int x, int y, int radius)
	{
		for(int i=0;i<brickList.size();i++)
		{
			Brick b = (Brick)brickList.get(i);
            int judge = b.judge(x, y, radius);
			if(judge != -1)
			{
				if(b.property == 0)
				{
					brickList.remove(i);
					count--;
				}
                if(isClear())
                	return -2;
                else
                	return judge;
			}
		}
		return -1;
	}
	
	public boolean isClear()
	{
		if(count == 0)
			return true;
		else
			return false;
	}
	
	public Brick isOn(int x, int y)
	{
		for(int i=0;i<brickList.size();i++)
		{
			Brick b = (Brick)brickList.get(i);
			if(b.judge(x,y) != -1)
			{
				brickList.remove(i);
				return b;
			}
		}
		return null;
	}
}